package HomeWork;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class HM8 {
    public static void main(String[] args) {

        ArrayList<Integer> poker = new ArrayList<>();
        Map<Integer, String> map = new HashMap<>();
        String[] colors = { "♥", "♣", "♦", "♠" };
        String[] numbers = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };

        poker.add(0);
        poker.add(1);

		Integer index = 2;
		map.put(0, "大王");
		map.put(1, "小王");
		for (String number : numbers) {
			for (String color : colors) {
				poker.add(index);
				map.put(index, color + number);
				index++;
			}
		}

        Collections.shuffle(poker);

        Player player1 = new Player("老王");
        Player player2 = new Player("老李");
        Player player3 = new Player("老刘");

        IntStream.range(0, poker.size())
                .filter(i -> i <= 51)
                .forEach(i -> {
                    List<Integer> playerList = (i % 3 == 0) ? player1.getList() : ((i % 3 == 1) ? player2.getList() : player3.getList());
                    playerList.add(poker.get(i));
                });
		Collections.sort(player1.getList());
		Collections.sort(player2.getList());
		Collections.sort(player3.getList());

        List<String> poker1 = player1.getList().stream().map(map::get).collect(Collectors.toList());
        List<String> poker2 = player2.getList().stream().map(map::get).collect(Collectors.toList());
        List<String> poker3 = player3.getList().stream().map(map::get).collect(Collectors.toList());

        System.out.println(poker1);
        System.out.println(poker2);
        System.out.println(poker3);
    }

    static class Player {
        private String name;
        private List<Integer> list;

        public Player(String name) {
            this.name = name;
            this.list = new ArrayList<>();
        }

        public List<Integer> getList() {
            return list;
        }
    }
}

//public class HM8 {
//	public static void main(String[] args) {
//
//		// 准备牌
//		ArrayList<Integer> poker = new ArrayList<Integer>();
//		ArrayList<String> poker1 = new ArrayList<String>();
//		ArrayList<String> poker2 = new ArrayList<String>();
//		ArrayList<String> poker3 = new ArrayList<String>();
//		Map<Integer, String> map = new HashMap();
//		// 定义两个数组
//		String[] colors = { "♥", "♣","♦" ,"♠"  };
//		String[] numbers = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
//		poker.add(0);
//		poker.add(1);
//		// 组装52张牌
//		Integer index = 2;
//		map.put(0, "大王");
//		map.put(1, "小王");
//		for (String number : numbers) {
//			for (String color : colors) {
//				poker.add(index);
//				map.put(index, color + number);
//				index++;
//			}
//		}
//
//		// 洗牌
//		Collections.shuffle(poker);
//
//		Player playe1 = new Player("老王");
//		Player playe2 = new Player("老李");
//		Player playe3 = new Player("老刘");
//		// 摸牌
//		for (int i = 0; i < poker.size(); i++) {
//			// 每一张牌
//			Integer p = poker.get(i);
//			if (i <= 51) {
//				if (i % 3 == 0) {
//					playe1.getList().add(p);
//				} else if (i % 3 == 1) {
//					playe2.getList().add(p);
//				} else {
//					playe3.getList().add(p);
//				}
//			}
//		}
//		Collections.sort(playe1.getList());
//		Collections.sort(playe2.getList());
//		Collections.sort(playe3.getList());
//		// 看牌
//		for (int i : playe1.getList()) {
//			poker1.add(map.get(i));
//		}
//		System.out.println(poker1);
//
//		for (int i : playe2.getList()) {
//			poker2.add(map.get(i));
//		}
//		System.out.println(poker2);
//
//		for (int i : playe3.getList()) {
//			poker3.add(map.get(i));
//		}
//		System.out.println(poker3);
//	}
//}